﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@* 种母配种添加 *@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <table>
                    <tr>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">采购员</label>
                                <div class="layui-input-block">
                                    <select id="purchaseName" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="张三">张三</option>
                                        <option value="李四">李四</option>
                                        <option value="王五">王五</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">采购日期</label>
                                <div class="layui-input-inline layui-input-wrap">
                                    <input type="date" id="purchaseTime" class="layui-input">
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">羊只类型</label>
                                <div class="layui-input-block">
                                    <select id="sheepType" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="0">公羊</option>
                                        <option value="1">母羊</option>
                                        <option value="2">后裔</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">类别</label>
                                <div class="layui-input-inline layui-input-wrap">
                                    <input type="date" id="purchaseCategory" class="layui-input">
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">核算单元</label>
                                <div class="layui-input-block">
                                    <select id="accountingUnit" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="默认">默认</option>
                                        <option value="销售部">销售部</option>
                                        <option value="人事部">人事部</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">供应商</label>
                                <div class="layui-input-block">
                                    <select id="vendorId" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="1">张三</option>
                                        <option value="2">李四</option>
                                        <option value="3">王五</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">仓库</label>
                                <div class="layui-input-block">
                                    <select id="wareHouse" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="一号仓">一号仓</option>
                                        <option value="二号仓">二号仓</option>
                                        <option value="三号仓">三号仓</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">摘要</label>
                                <div class="layui-input-block">
                                    <select id="abstract" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="外购转入">外购转入</option>
                                        <option value="内购转入">内购转入</option>
                                        <option value="统购转入">统购转入</option>
                                        <option value="直营转出">直营转出</option>
                                        <option value="期初">期初</option>
                                        <option value="仓库期初">仓库期初</option>
                                        <option value="联营转入">联营转入</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">单据号</label>
                                <div class="layui-input-inline layui-input-wrap">
                                   --
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">流水号</label>
                                <div class="layui-input-block">
                                    --
                                </div>
                            </div>
                        </td>
                        <td></td>
                    </tr>
                </table>
                <button type="button" class="layui-btn layui-bg-red" onclick="Add()" lay-on="test-iframe-curl">新增</button>

            </div>
        </div>


        <table class="layui-table" style="width:200%">
            <thead>
                <tr>
                    <td>耳号</td>
                    <td>栋舍</td>
                    <td>转入栏位</td>
                    <td>性别</td>
                    <td>商品名称</td>
                    <td>标包</td>
                    <td>计量单位</td>
                    <td>入库数量</td>
                    <td>只均单价</td>
                    <td>金额</td>
                    <td>单位折扣</td>
                    <td>调整金额</td>
                    <td>结算金额</td>
                    <td>总重量</td>

                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="recordAuricle" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <select id="cottageId" lay-filter="provincet">
                            <option value="-1">请选择</option>
                        </select>
                    </td>
                    <td>
                        <select id="field" lay-filter="city">
                            <option value="-1">请选择</option>
                        </select>
                    </td>
                    <td>
                        <select id="sex" lay-filter="testSelect">
                            <option value="-1">请选择</option>
                            <option value="0">公</option>
                            <option value="1">母</option>
                        </select>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="goodName" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="package" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="measurement" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="storage" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="purchasePrice" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="purchaseNumPrice" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="purchaseDiscount" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="purchaseAdjust" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="purchaseSettle" class="layui-input">
                        </div>
                    </td>
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="purchaseWeight" class="layui-input">
                        </div>
                    </td>
                    
                    
                </tr>
            </tbody>
        </table>


        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" id="remark"></textarea>
            </div>
        </div>


    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        layui.use('form', function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;

            //绑定耳号
            bangsheng1();
            //绑定栋舍
            bangsheng();


            //绑定栋舍
            function bangsheng() {
                $.ajax({
                    url: "http://localhost:5123/api/Cottage/CottageSecondaryQuery",
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $.each(res.data, function () {
                            $("#cottageId").append(`<option value="${this.cottageId}">${this.cottageName}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框
                    }
                })
            }

            //获取栋舍下拉框的值
            form.on('select(provincet)', function (data) {
                provincetId1 = data.value;
                console.log(provincetId1, 15152)
                $("#field").empty();
                $("#field").append('<option value="">请选择</option>');
                bangshi()

            });

            //绑定栏位
            function bangshi() {
                var cottageId = $("#cottageId").val();
                $.ajax({
                    url: "http://localhost:5123/api/Field/GetFieldCottage",
                    data: JSON.stringify({ cottageId: cottageId }),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res.data)

                        $.each(res.data, function () {
                            $("#field").append(`<option value="${this.fieldId}">${this.fieldName}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框
                    }

                })
            }

            //绑定耳号
            function bangsheng1() {

                $.ajax({
                    url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $.each(res.data, function () {
                            $("#earBugles").append(`<option value="${this.recordAuricle}">${this.recordAuricle}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框

                    }

                })
            }

            

        })





        //配种新增
        function Add() {
            var data = {
                purchaseName: $("#purchaseName").val(),
                purchaseTime: $("#purchaseTime").val(),
                sheepType: $("#sheepType").val(),
                purchaseCategory: $("#purchaseCategory").val(),
                accountingUnit: $("#accountingUnit").val(),
                vendorId: $("#vendorId").val(),
                abstract: $("#abstract").val(),
                prchaseNumber: $("#prchaseNumber").val(),
                recordAuricle: $("#recordAuricle").val(),
                cottageId: $("#cottageId").val(),
                field: $("#field").val(),
                sex: $("#sex").val(),
                goodName: $("#goodName").val(),
                package: $("#package").val(),
                measurement: $("#measurement").val(),
                storage: $("#storage").val(),
                purchasePrice: $("#purchasePrice").val(),
                purchaseNumPrice: $("#purchaseNumPrice").val(),
                purchaseDiscount: $("#purchaseDiscount").val(),
                purchaseAdjust: $("#purchaseAdjust").val(),
                purchaseSettle: $("#purchaseSettle").val(),
                purchaseWeight: $("#purchaseWeight").val(),
            }

            $.ajax({
                url: "http://localhost:5269/api/SheepPurchase/CreatePurchase",
                type: 'post',
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.msg('添加成功')
                        location.href = "/Purchase/PurchaseIndex"
                    }
                    else {
                        layer.msg('保存失败')
                    }
                }
            })
        }

    </script>


</body>

</html>